package com.example.planetexploder.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.planetexploder.R;
import com.example.planetexploder.bean.otherdata.MenuItem;

import java.util.ArrayList;

public class MyAdapter_MenuEdit extends BaseAdapter {
    private ArrayList<MenuItem> mList;
    private Context mContext;
    private TextView grid_text;
    private View deleteView;
    private boolean isShowDelete;// 根据这个变量来判断是否显示删除图标，true是显示，false是不显示

    public MyAdapter_MenuEdit(Context mContext,
                              ArrayList<MenuItem> myList) {
        this.mContext = mContext;
        this.mList = myList;
    }

    public void setIsShowDelete(boolean isShowDelete) {
        this.isShowDelete = isShowDelete;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {

        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.listviewedit_item,null);
        grid_text = convertView.findViewById(R.id.textEdit_Listview);
        deleteView = convertView.findViewById(R.id.listDeleteMenuEdit);
        deleteView.setVisibility(isShowDelete ? View.VISIBLE : View.GONE);// 设置删除按钮是否显示
        grid_text.setText(mList.get(position).getTitle());
        return convertView;
    }
}